newfileout = 0;
newdirout = 0;
uploadout = 0;
editorout = 0;

function ajaxfade(script, outputdiv)
{
    var hoehe = $("#slider").height();
	if(hoehe == 0)
	{
		$(outputdiv).html("<center><div style=\"padding:15px\"><img src=\"images/ajax-loader.gif\" style=\"display: block; padding-bottom: 10px\" />Lade...</div></center>");
	}
	
	$("#loader").fadeToggle("fast");

	$.get(script, function(data)
	{
	    $(outputdiv).html(data);
		$(outputdiv).hide();
		$(outputdiv).fadeToggle("");
		$("#ajaxdiv").css("height", "auto");
    });   
}

function newdirectory(curdir)
{	
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(uploadout == 1 || newfileout == 1 || editorout == 1)
			{
				$.get('../ajax/newdirectory.php?dir='+curdir+'', function(data)
				{
					n.html(data);
					$("#actDir").html(curdir);	
	    			n.animate({top: '0px'}, 'slow');
	    			n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
	    		});
		    	uploadout = 0;
		    	newfileout = 0;	
		    	editorout = 0;
		    	newdirout = 1;	
			}
			else
			{
				newdirout = 0;
			}
		});
	}
	else
	{
		$.get('../ajax/newdirectory.php?dir='+curdir+'', function(data)
		{
			n.html(data);
			$("#actDir").html(curdir);	
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    	});
    	newdirout = 1;		
	}
}

function newfile(curdir)
{	
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(uploadout == 1 || newdirout == 1 || editorout == 1)
			{
				$.get('../ajax/newfile.php?dir='+curdir+'', function(data)
				{
					n.html(data);
					$("#actDir").html(curdir);	
		    		n.animate({top: '0px'}, 'slow');
		    		n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
		    	});
		    	uploadout = 0;
		    	newdirout = 0;
		    	editorout = 0;
		    	newfileout = 1;		
			}
			else
			{
				newfileout = 0;
			}
		});
	}
	else
	{
		$.get('../ajax/newfile.php?dir='+curdir+'', function(data)
		{
			n.html(data);
			$("#actDir").html(curdir);	
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    	});
    	newfileout = 1;		
	}
}

function rename(old, curdir, type, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader").fadeToggle("fast");
		m.css('display', 'block');
	    
	    $.get('../ajax/rename.php?type=' + type + '&curdir=' + curdir + '&old=' + old + '', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader").fadeToggle("fast");
		});
	}
}

function edit(editfile, num, curdir)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);
	
	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader").fadeToggle("fast");
		m.css('display', 'block');
	    
	    $.get('../ajax/edit.php?dir='+curdir+'&file='+editfile+'', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader").fadeToggle("fast");
		});
	}
}

function deletest(todelete, curdir, type, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader").fadeToggle("fast");
	    m.css('display', 'block');
	    $.get('../ajax/delete.php?type='+type+'&delete='+todelete+'&dir='+curdir+'', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader").fadeToggle("fast");
		});
	}
	m.css('display', 'block');
}

function chmod(chmod, tochmod, curdir, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader").fadeToggle("fast");
	    m.css('display', 'block');
	    $.get('../ajax/chmod.php?chmod=' + chmod + '&tochmod=' + tochmod + '&dir=' + curdir + '', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader").fadeToggle("fast");
		});
	}
	m.css('display', 'block');
}

function upload(curdir)
{
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(newfileout == 1 || newdirout == 1 || editorout == 1)
			{
				$.get('../ajax/upload.php?dir='+curdir+'', function(data)
				{
					n.html(data);
		    		n.animate({top: '0px'}, 'slow');
		    		n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
		    	});
		    	newdirout = 0;
		    	newfileout = 0;	
		    	editorout = 0;	
		    	uploadout = 1;
			}
			else
			{
				uploadout = 0;
			}
		});
	}
	else
	{
		$.get('../ajax/upload.php?dir='+curdir+'', function(data)
		{
			n.html(data);
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    	});
    	uploadout = 1;
	}
}

function closeNotification()
{
	$(".notification").fadeOut("slow");
}

function savefile(filetosave, curdir)
{
	$("#loader").fadeToggle("fast");
	var code = $('#code').val();
	
	$.post( 
		'../ajax/showdirectory.php?dir='+curdir+'', 
		{ 
			newfilecontent: code, 
			filetosave   : filetosave
		},
		function(data)
		{
			$('#slider').html(data);
			$('#slider').hide();
			$('#slider').fadeToggle("");
			$("#ajaxdiv").css("height", "auto");
		}
	);
}